/* your js go here */
$(function () {

    $("#avatar").click(function () {
        console.log("你点击了头像");
        window.location.href = '/view/userLook'
    });

    //file表单选中文件时,让file表单的val展示到showname这个展示框
    $('#myFile').change(function () {
        // $('#showname').val($(this).val())
        var filename = $(this).val();
        console.log(filename);
        var file = $('#myFile')[0].files[0];
        var formData = new FormData();
        formData.append("file",file);
        $.ajax({
            url: '/user/uploadFile',
            type:'POST',
            data: formData,
            processData : false, // 使数据不做处理
            contentType : false, // 不要设置Content-Type请求头
            success: function(data){
                if('fail' !== data){
                    $("#myPic").attr("src",data);
                    $("#myHeadPic").attr("src",data);
                }
            },
            error:function(response){
                console.log(response);
            }
        });

    });

    //用户列表，查看详情，通过class名字userDetail来找
    $(".userDetail").click(function () {
        console.log("你点击了用户详情");
        var userId = $(this).attr("data-id");
        window.location.href = '/user/getDetail?userId=' + userId;
    });

    //发布会议跳转链接
    $("#addMeet").click(function () {
        window.location.href = '/view/meetAdd'
    });

    //添加文章跳转链接
    $("#addArt").click(function () {
        window.location.href = '/view/artAdd'
    });

    $(".myList>ul>li").on("click",function () {
        if($(this).find("div").attr('class')=='list-group myGroup isHidden'){
            $(this).find("div").removeClass("isHidden")
        }else{
            $(this).find("div").addClass("isHidden")
        }

    });

    $(".myUserList>ul>li>div").on("click",function () {
        $(this).parent().addClass("isHidden");
        var url="/user/delUserFocus";
        var data={
            focusid:$(this).find("input[type='submit']").attr("name")
        };
        var callback=function (result) {
        };
        var type="json";
        $.post(url,data,callback,type);
    });

    $(".table").find("input[type='checkbox']").on("click",function () {
        var data={
            focusid:$(this).val()
        };
        var callback=function (result) {
        };                     
        var type="json";
        if($(this).prop("checked")){
            var url="/user/addUserFocus";
            layer.msg("关注成功")
        }else{
            var url="/user/delUserFocus";
            layer.msg("取关成功")
        }
        $.post(url,data,callback,type);
    });
});

//触发隐藏的file表单
function makeThisfile() {
    $('#myFile').click();
}